package lego.jbv;

import lejos.nxt.SensorPort;
import lejos.nxt.TouchSensor;
import lejos.robotics.subsumption.Behavior;

public class Attack implements Behavior {
	private TouchSensor touchFront;
	private final int maxSpeed = 100;
	private boolean _suppressed = false;
	private Car car;
	
	public Attack(SensorPort front, Car _car)
	{
		car = _car;
		touchFront = new TouchSensor(front);
	}

	@Override
	public boolean takeControl() {
		return touchFront.isPressed();
	}

	@Override
	public void action() {
		_suppressed = false;

		while (!_suppressed && touchFront.isPressed()) {
			car.drive(maxSpeed, true);
			
			Thread.yield(); //TODO: Might not be necessary.
		}
	}

	@Override
	public void suppress() {
		_suppressed = true;
	}

}
